#include "stdafx.h"
#include "WaitingUserManager.h"

WaitingUserManager::WaitingUserManager(void)
{
}

WaitingUserManager::~WaitingUserManager(void)
{
}

void WaitingUserManager::RegisterUser(DWORD user_id, DWORD ip, DWORD msg_id, DWORD overlap_index)
{
	waiting_users_.insert(std::make_pair(user_id, WaitingUserContext(user_id, ip, msg_id, overlap_index)));
}

void WaitingUserManager::UnregisterUser(DWORD user_id)
{
	waiting_users_.erase(user_id);
}

WaitingUserContext* WaitingUserManager::GetUserContext(DWORD user_id)
{
	return const_cast<WaitingUserContext*>(FindUserContext(user_id));
}

const WaitingUserContext* WaitingUserManager::FindUserContext(DWORD user_id) const
{
	auto it = waiting_users_.find(user_id);
	if (it == waiting_users_.end())
		return nullptr;

	return &(it->second);
}

void WaitingUserManager::UpdateUserContext(DWORD user_id, DWORD ip, DWORD msg_id, DWORD overlap_index)
{
	WaitingUserContext* context = GetUserContext(user_id);
	if (context == nullptr)
		return;

	context->ip = ip;
	context->msg_id = msg_id;
	context->overlap_index = overlap_index;
}